/* Fenwick tree */

#include <cstdio>
#include <vector>
using namespace std;

int RSQ(const vector<int>& T, int i) //find sum [0, i]
{
	int sum = 0;

	while (i >= 0)
	{
		sum += T[i];
		i = (i & (i+1)) - 1;
	}
	return sum;
}

int RSQ(const vector<int>& T, int i, int j) //find sum [i, j]
{
	return RSQ(T, j) - RSQ(T, i-1);
}

void update(vector<int>& T, int i, int delta)
{
	while (i < T.size())
	{
		T[i] += delta;
		i = i | (i+1);
	}
}

void buildTree(const vector<int>& A, vector<int>& T)
{
	T.resize(A.size());
	T.assign(T.size(), 0);

	for (int i = 0; i < T.size(); ++i)
		update(T, i, A[i]);
}

int main()
{
	int N; // size of array of numbers

	scanf("%d", &N);

	vector<int> A(N), // array
			    T(N); // Fenwick tree

	for (int i = 0; i < N; ++i)
		scanf("%d", &A[i]);
	
	buildTree(A, T);

	int i, j;

	// many queries of the form "i j" until "-1 -1" comes
	while (scanf("%d%d", &i, &j) == 2 && i >= 0 && j >= 0)
	{
		int sum = RSQ(T, i, j);
		printf("%d\n", sum);
	}
}
